const koaRouter = require('koa-router')
const router = new koaRouter({
    prefix:'/api/auth'
})

const User = require('../model/user')
const Code = require('../model/code')
const { LoginValidator,CodeLoginValidator} = require('../validater')

// 用户登录
router.post('/login', async ctx => {
    const v = new LoginValidator().validate(ctx)
    const { username, password } = v.get('body')
    await User.login(username,password,ctx)
})

// 短信登录
router.post('/codeLogin', async ctx => {
    const v = new CodeLoginValidator().validate(ctx)
    const {phone,code} = v.get('body')
    await User.codeLogin(phone, code, ctx)
})

module.exports = router